Skip to content

Fix: Users Unable to Upload Product Images if the store is private #12824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

pmusolino
Copy link
Contributor

Closes: #12646

Description

The PR adds a notice in Product detail when a WP.com site is in Private mode since this makes the images not accessible.
This happens just on WP.com sites, since on self-hosted store it's not possible to put a store in the "private" state.
This has been already fixed here woocommerce/woocommerce-android#11383 and here woocommerce/woocommerce-android#11493 on Android.

Detail implementation

I decided to use a custom table view cell inside the image section instead of showing it as a banner, because it can happen to have another banner already displayed while the user is editing a product (or it can appear later). In this way, this notice in product images is always displayed when the store is private.

Testing instructions

Test 1

  1. Log in to a WP.com site that is Public
  2. Go to Products -> Tap on some product
  3. Verify the images are available (either existing images or button to add one)
  4. In wp-admin set the site to Private mode in Settings (more info here)
  5. In the app, switch to a different site and switch back (or re-login, or close and reopen the app)
  6. Go to Products -> Tap on some product
  7. Verify a notice is displayed instead of an image gallery
  8. Tap on the notice
  9. Verify the privacy settings page is opened
  10. Go back
  11. In wp-admin set the site to Coming soon mode in the Settings
  12. In the app, switch to a different site and switch back (or re-login, or close and reopen the app)
  13. Go to Products -> Tap on some product
  14. Verify the images are available (either existing images or button to add one)

Test 2

  1. Create a self-hosted site with WooCommerce but without installing Jetpack or connecting a WP.com user using JCP
  2. Log in to the app
  3. Start creating a product
  4. Verify the image uploading is available

Screenshots

Light mode Dark mode
Simulator Screenshot - iPhone 15 Pro Max - 2024-05-23 at 18 34 58 Simulator Screenshot - iPhone 15 Pro Max - 2024-05-23 at 18 35 11

  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@pmusolino pmusolino added the feature: add/edit products Related to adding or editing products. label May 23, 2024
@pmusolino pmusolino added this to the 18.8 milestone May 23, 2024
@pmusolino pmusolino changed the title Fix: Users Unable to Upload Product Images on iOS App if the store is private Fix: Users Unable to Upload Product Images if the store is private May 23, 2024
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented May 23, 2024

WooCommerce iOS📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr12824-fde919c
Version18.9
Bundle IDcom.automattic.alpha.woocommerce
Commitfde919c
App Center BuildWooCommerce - Prototype Builds #9412
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@jaclync jaclync modified the milestones: 18.8, 18.9 May 24, 2024
@itsmeichigo itsmeichigo self-assigned this May 27, 2024
Copy link
Contributor

@itsmeichigo itsmeichigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @pmusolino! This test didn't pass for me:

In wp-admin set the site to Coming soon mode in the Settings
In the app, switch to a different site and switch back (or re-login, or close and reopen the app)
Go to Products -> Tap on some product
Verify the images are available (either existing images or button to add one)

/// Returns true only if the site is hosted on WP.com and is private.
///
var isPrivateWPCOMSite: Bool {
return isWordPressComStore && !isPublic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic includes only public sites. Is it possible to access images for sites with Coming soon status?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not expected, unfortunately. As you can see here C06NC969ZF0/p1715793466695389?thread_ts=1715193928.110329&cid=C06NC969ZF0 I was expecting that parsing blog_public limiting it to Atomic websites return private = true only if the store is private and not coming soon or public.

It seems btw that the app parse isPublic alias blog_public as a boolean, while it's an integer. From my tests, the values should be private = -1, coming soon = 0, public = 1. When it's -1, it's automatically false, that's why it works as expected. When it's coming soon, it's also false (0), and that's why you see the banner.

I'm going to address this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itsmeichigo this is ready for another review!
Here are all the changes: a91a6fc

Below is the list of changes:

  • I removed the isPublic property from the Site model, which has been replaced with visibility, a property of type SiteVisibility. SiteVisibility is an enum that contains the values private = -1, coming soon = 0, public = 1.
  • Following the above change, I created a new Core Data model (version 112). As there is a data migration involved from the old Boolean value to the new Int64 in the database, there is also a new mapping model that converts the old Boolean value from model version 111 to the new Int64 in model version 112.
  • I updated all the code to use the new visibility property.

@dangermattic
Copy link
Collaborator

dangermattic commented May 30, 2024

1 Warning
⚠️ This PR is larger than 500 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@pmusolino pmusolino requested a review from itsmeichigo May 30, 2024 18:06
Copy link
Contributor

@itsmeichigo itsmeichigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found issues with self-hosted sites when checking their visibility to display the Share option for products and Test order on the Orders tab, so I pushed a commit to fix that.

Although this works as described now, I'm not confident I didn't miss any edge cases. There aren't any migration tests for the migration from Core Data model version V111 to 112, and it's quite close to the code freeze, it's safer to delay the merge until the next version.

@@ -49,7 +49,7 @@ final class OrderListViewModel {
}

/// Enabled if site is launched, has published at least 1 product and set up payments.
return site.isPublic && hasAnyPaymentGateways && hasAnyPublishedProducts
return (site.visibility == .publicSite) && hasAnyPaymentGateways && hasAnyPublishedProducts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails for self-hosted sites because you were setting the default visibility for them as .comingSoon. I pushed a change in 44036af to make them public by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is likely an error that existed previously since the WordPressSite had the isPublic property set to false, which was equivalent to comingSoon. Therefore, with the configuration I had in place, there should not have been any difference in behavior.

@hafizrahman hafizrahman modified the milestones: 18.9, 19.0 May 31, 2024
@pmusolino
Copy link
Contributor Author

Added the test for the migration from Core Data model version V111 to 112 408181a

Copy link
Contributor

@itsmeichigo itsmeichigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the migration test Paolo!

@pmusolino pmusolino enabled auto-merge June 3, 2024 09:05
@pmusolino pmusolino merged commit f067b31 into trunk Jun 3, 2024
22 checks passed
@pmusolino pmusolino deleted the issue/12646-Users-Unable-to-Upload-Product-Images-on-iOS-App-if-the-store-is-private branch June 3, 2024 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: add/edit products Related to adding or editing products.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Users Unable to Upload Product Images on iOS App if the store is private
6 participants